package com.tarena.seata.cart.web.rpc;

import com.tarena.seata.api.CartApi;
import com.tarena.seata.cart.web.mapper.CartMapper;
import java.util.Random;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class CartApiImpl implements CartApi {
    @Autowired
    private CartMapper cartMapper;
    private Boolean flag=true;
    @Transactional(rollbackFor = Exception.class)
    @Override public void delCart(String userId, String productCode) {
        cartMapper.delCart(userId, productCode);
        System.out.println("删除购物车失败,其他分支回滚");
        if (flag){//50%
            throw new RuntimeException("删除购物车失败");
        }
    }
}
